define([
        "dojo/_base/declare",
        "gistech/widgets/baseWidget/BaseWidget",
        "dojo/dnd/move",
        "dojo/text!./templates/ConfirmDialog.html",
        "dojo/text!./templates/shelter.html"],
        function(declare,BaseWidget,Move,template,shelter){
            return declare([BaseWidget],{
        		shelterDom:null,//遮罩层节点
        	    titleStr:"Prompt",//标题
        	    contentStr:"",//内容
        	    okStr:"",
        	    cancelStr:"",
        	    hasConfig:false,
        	    templateString:template,
        	    
        	    constructor:function (args) {
        	        if (args) {
        	            if (args.titleStr) {
        	                this.titleStr = args.titleStr;
        	            }
        	            if (args.contentStr) {
        	                this.contentStr = args.contentStr;
        	            }
        	            if(args.okStr){
        	            	this.okStr = args.okStr;
        	            }
        	            if(args.cancelStr){
        	            	this.cnacelStr = args.cancelStr;
        	            }
        	        }
        	    },

        	    postCreate:function () {
        	        this.setTitle();
        	        this.setContent();
        	        new dojo.dnd.Moveable(this.domNode, {handle:this.head});
        	        dojo.connect(this.close, "onclick", this, this.closeDialog);
        	        dojo.connect(this.confirm, "onclick", this, this.onConfirmClick);
        	        dojo.connect(this.cancel, "onclick", this, this.onCancelClick);
        	        dojo.connect(window, "onresize", this, this.onWidowResize);

        	        var shelterHtml = shelter;
        	        this.shelterDom = dojo.place(shelterHtml, dojo.body());
        	        var zIndexShelter = dojo.style(this.shelterDom, "zIndex");
        	        dojo.style(this.domNode, "zIndex", zIndexShelter + 1);//要保证小部件位于遮罩层之上
        	        dojo.style(this.domNode, "position", "absolute");
        	        dojo.place(this.domNode, dojo.body());
        	    },

        	    //显示widget
        	    show:function () {
        	        this._position();
        	        if(this.okStr){
        	        	this.confirm.innerHTML = this.okStr;
        	        }
        	        if(this.cancelStr){
        	        	this.cancel.innerHTML = this.cancelStr;
        	        }
        	        return new dojo.Deferred();
        	    },

        	    //设置标题
        	    setTitle:function () {
        	        this.headTitle.innerHTML = this.titleStr;
        	    },

        	    //设置提示内容
        	    setContent:function () {
        	        this.content.innerHTML = this.contentStr;
        	    },

        	    //确认的listener
        	    onConfirmClick:function () {
        	        this.onConfirm();
        	        this.onClose();
        	    },

        	    //确认事件
        	    onConfirm:function () {
        	    },

        	    //取消的listener
        	    onCancelClick:function () {
        	        this.onCancel();
        	        this.onClose();
        	    },

        	    //取消事件
        	    onCancel:function () {
        	    },

        	    //关闭
        	    closeDialog:function () {
        	        this.onClose();
        	    },

        	    //关闭事件
        	    onClose:function () {
        	        if (this.shelterDom) {
        	            dojo.destroy(this.shelterDom);
        	            this.shelterDom = null;
        	        }
        	        this.destroy();
        	    },

        	    //window尺寸改变事件
        	    onWidowResize:function (evt) {
        	        this._position();
        	    },

        	    //定位
        	    _position:function () {
        	        if (this.domNode) {
        	            var thisWidth = this.domNode.clientWidth;
        	            var thisHeight = this.domNode.clientHeight;
        	            var box = dojo.window.getBox();
        	            var left = (box.w - thisWidth) / 2;
        	            var top = (box.h - thisHeight) / 2;
        	            dojo.style(this.domNode, "left", left + "px");
        	            dojo.style(this.domNode, "top", top + "px");
        	        }
        	    },

        	    /**
        	     * 添加按钮并绑定click事件
        	     * @param text 按钮文本
        	     * @param listener click的listener
        	     * @param domain listener的作用域
        	     */
        	    addButton:function (text, listener, domain) {
        	        var btn = dojo.create("a", {href:"javascript:;", innerHTML:text}, this.foot);
        	        dojo.connect(btn, "onclick", domain, listener);
        	        this._position();
        	        return btn;
        	    }
            });
})